home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 114 / macaddict114.cdr / Software / Internet & Communication / IOXWebcamX-1.1.dmg / IOXWebcamX-1.1.pkg / Contents / Resources / VideoInstallerTools.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2005-05-05  |  24.2 KB  |  798 lines

  1. #!/bin/sh -x
  2.  
  3.  
  4. # TODO - clean up code - move existence tests to the change permissions/owner/group functions.
  5. # TODO - write a fix bundle function which takes args for the permission of the executable.
  6. # TODO - validate arguments
  7. # TODO - generate .sh file which is sourced to define names and locations of all apps.
  8.  
  9. # ----------------------------------------------------------------------------
  10. #
  11. # Take $1 $2 and $3 and convert to
  12. #     PACKAGE_NAME, VARIANT, VOLUME, and INSTALLER_TOOLS_DIR
  13. #    $1 is expected to be the full path to the installer .pkg
  14. #
  15. #
  16. function processPreflightArgs()
  17. {
  18.     P="$1"
  19.     PACKAGE_NAME=`/usr/bin/basename "${P}" .pkg`
  20.     VARIANT=${PACKAGE_NAME#*-}
  21.     if [ "${VARIANT}" = "${PACKAGE_NAME}" ]
  22.     then
  23.         VARIANT=""
  24.     else
  25.         VARIANT="-${VARIANT}"
  26.     fi
  27.     
  28.     INSTALLER_TOOLS_DIR="$1/Contents/Resources"
  29. }
  30.  
  31. # ----------------------------------------------------------------------------
  32. #
  33. # Take $1 $2 and $3 and convert to
  34. #     PACKAGE_NAME, VARIANT, VOLUME, and INSTALLER_TOOLS_DIR
  35. #    $1 is expected to be the full path to the installer .pkg
  36. #
  37. #
  38. function processPostflightArgs()
  39. {
  40.     P="$1"
  41.     PACKAGE_NAME=`/usr/bin/basename "${P}" .pkg`
  42.     
  43.     // Extract the Variant from the package name
  44.     VARIANT=""
  45.     if [ "${PACKAGE_NAME}" != "${PACKAGE_NAME%-Log}" ]
  46.     then
  47.         VARIANT="-Logging"
  48.     
  49.     elif [ "${PACKAGE_NAME}" != "${PACKAGE_NAME%-Dbg}" ]
  50.     then
  51.         VARIANT="-Debug"
  52.     fi
  53.         
  54.     # Determine the Destination Volume
  55.     
  56.     VOLUME=$3
  57.     if [ "${VOLUME}" = "/" ]
  58.     then
  59.         VOLUME=""
  60.     fi
  61.     
  62.     INSTALLER_TOOLS_DIR="$1/Contents/Resources"
  63. }
  64.  
  65. # ----------------------------------------------------------------------------
  66.  
  67. function bailOnError()
  68. {
  69.     if test "$1" -ne 0; then
  70.         exit 1
  71.     fi
  72. }
  73.  
  74. # ----------------------------------------------------------------------------
  75.  
  76. function showInstallerState()
  77. {
  78.     echo "  "
  79.     echo "-------------------------------------------------------------"
  80.     echo "$1"
  81.     echo "  "
  82.     echo "  "
  83. }
  84.  
  85. # Functions to conveniently set
  86. #     user, group, and permissions
  87.  
  88. # ----------------------------------------------------------------------------
  89. # fixPermissions group <permissions> <filename>
  90. function fixPermissions()
  91. {
  92.     set -x
  93.     /bin/chmod "$2" "$3"
  94.     /usr/bin/chgrp "$1" "$3"
  95.     set +x
  96. }
  97.  
  98. # ----------------------------------------------------------------------------
  99. # recurseFixPermissions <group> <permissions> <filename>
  100. function recurseFixPermissions()
  101. {
  102.     set -x
  103.     /bin/chmod     -R "$2" "$3"
  104.     /usr/bin/chgrp -R "$1" "$3"
  105.     set +x
  106. }
  107.  
  108. # ----------------------------------------------------------------------------
  109. # recurseFixOwnership group user filename
  110. function recurseFixOwnership()
  111. {
  112.     set -x
  113.     sudo /usr/sbin/chown -R "$2" "$3"
  114.     sudo /usr/bin/chgrp  -R "$1" "$3"
  115.     set +x
  116. }
  117.  
  118. # ----------------------------------------------------------------------------
  119. # exit script with error if symbol named $2 with value $1 doesn't exist as a file
  120. # system object.
  121. # TODO - disable and restore echoing during these functions
  122. function assertExistFileSystemObject()
  123. {
  124.     # if name is ''
  125.     if [ "x$1" == "x" ]
  126.     then
  127.         echo $2 "is undefined"
  128.         exit 1
  129.     fi
  130.     # if name exists
  131.     if ! [ -e "$1" ]
  132.     then
  133.         echo $2 " == " $1 " doesn't exist"
  134.         exit 1
  135.     fi
  136. }
  137.  
  138. # ----------------------------------------------------------------------------
  139. # exit script with error if symbol $2 with value $1 doesn't exist or isn't a directory
  140. function assertExistDir()
  141. {
  142.     assertExistFileSystemObject "$1" "$2"
  143.     # if name is dir
  144.     if ! [ -d "$1" ]
  145.     then
  146.         echo $2 " == " $1 " is not a directory"
  147.         exit 1
  148.     fi
  149. }
  150.  
  151. # ----------------------------------------------------------------------------
  152. # exit script with error if symbol $2 with value $1 doesn't exist or isn't a directory
  153. function assertDefinedString()
  154. {
  155.     if  [ -z "$1" ]
  156.     then
  157.         echo $2 " == " $1 " is not a file"
  158.         exit 1
  159.     fi
  160. }
  161.  
  162. # ----------------------------------------------------------------------------
  163. # exit script with error if symbol $2 with value $1 doesn't exist or isn't a directory
  164. function assertExistFile()
  165. {
  166.     assertExistFileSystemObject "$1" "$2"
  167.     # if name is file
  168.     if ! [ -f "$1" ]
  169.     then
  170.         echo $2 " == " $1 " is not a file"
  171.         exit 1
  172.     fi
  173. }
  174.  
  175. # ----------------------------------------------------------------------------
  176. # exit script with error if symbol $2 with value $1 doesn't exist or isn't an executable
  177. function assertExistExecutable()
  178. {
  179.     assertExistFileSystemObject "$1" "$2"
  180.     # if name is executable
  181.     if ! [ -x "$1" ]
  182.     then
  183.         echo $2 " == " $1 " is not executable"
  184.         exit 1
  185.     fi
  186. }
  187.  
  188. # ----------------------------------------------------------------------------
  189. # exit script with error if symbol $2 with value $1 doesn't exist or isn't a directory
  190. function assertExistAppBundle()
  191. {
  192.     assertExistDir  "$1"                        "$2"
  193.     assertExistDir  "$1/Contents"                "$2/Contents"
  194.     assertExistDir  "$1/Contents/Resources"        "$2/Resources"
  195.     assertExistDir  "$1/Contents/MacOS"            "$2/MacOS"
  196.     assertExistFile "$1/Contents/Info.plist"    "$2/Contents/Info.plist"
  197.     assertExistFile "$1/Contents/PkgInfo"        "$2/Contents/PkgInfo"
  198. }
  199.  
  200. # ----------------------------------------------------------------------------
  201. function moveToTrash()
  202. {
  203.     __TRASH_ITEM__="$1"
  204.     if [ -e "${__TRASH_ITEM__}" ]
  205.     then
  206.         assertExistExecutable  "${INSTALLER_TOOLS_DIR}/MoveToTrash" "-MoveToTrash-"
  207.         # TODO - MoveToTrash >might< need seduid permission bit set.
  208.         set -x
  209.         "${INSTALLER_TOOLS_DIR}/MoveToTrash" "${__TRASH_ITEM__}"
  210.         set +x
  211.     fi
  212. }
  213.  
  214. # ----------------------------------------------------------------------------
  215. function moveVariantsToTrash()
  216. {
  217.     moveToTrash "$1$2"
  218.     moveToTrash "$1-Debug$2"
  219.     moveToTrash "$1-Logging$2"
  220. }
  221.  
  222. # ----------------------------------------------------------------------------
  223. # defineInstallLocations
  224. #     expects VOLUME to be defined
  225. #
  226. #    defines the following directories
  227. #        APPLICATION_SUPPORT_DIR
  228. #        APPLICATION_SUPPORT_BIN_DIR
  229. #        APPLICATION_DIR
  230. #        COMPONENTS_DIR
  231. #        SYSTEM_EXTENSIONS_DIR
  232. #        STARTUP_ITEMS
  233. #        SYSTEM_STARTUP_ITEMS
  234. #
  235.  
  236. function defineInstallLocations()
  237. {
  238.     VENDOR_SUBDIR="$1"
  239.     VENDOR_APP_SUBDIR="$2"
  240.     APPLICATION_SUPPORT_DIR="${VOLUME}/Library/Application Support/${VENDOR_SUBDIR}"
  241.     APPLICATION_SUPPORT_BIN_DIR="${APPLICATION_SUPPORT_DIR}/Private"
  242.     APPLICATION_DIR="${VOLUME}/Applications/${VENDOR_APP_SUBDIR}"
  243.     COMPONENTS_DIR="${VOLUME}/Library/Components"
  244.     SYSTEM_EXTENSIONS_DIR="${VOLUME}/System/Extensions"
  245.     STARTUP_ITEMS="${VOLUME}/Library/StartupItems"
  246.     SYSTEM_STARTUP_ITEMS="${VOLUME}/System/Library/StartupItems"
  247. }
  248.  
  249.  
  250. # ----------------------------------------------------------------------------
  251.  
  252. function fixBasicDirectoryPermissions()
  253. {
  254.     assertExistDir  "${VOLUME}/Library"                        "-Library-"
  255.     assertExistDir  "${VOLUME}/Library/Components"            "-Library/Components-"
  256.     assertExistDir  "${VOLUME}/Library/Application Support" "-Library/Application Support-"
  257.     
  258.     fixPermissions         admin 775  "${VOLUME}/Library"
  259.     fixPermissions         admin 775  "${VOLUME}/Library/Components"
  260.     fixPermissions         admin 775  "${VOLUME}/Library/Application Support"
  261. }
  262.  
  263.  
  264. # ----------------------------------------------------------------------------
  265. # Fixes permissions for various directories
  266. #   Shouldn't be necessary except for perhaps support and device keys.
  267.  
  268. function fixDirectoryPermissions()
  269. {
  270.     showInstallerState "Fixing Directory Permissions"
  271.     
  272.     assertExistDir  "${APPLICATION_SUPPORT_DIR}" "APPLICATION_SUPPORT_DIR"
  273.     assertExistDir  "${APPLICATION_SUPPORT_DIR}/Device Keys" "-Device Keys Dir-"
  274.     assertExistDir  "${APPLICATION_SUPPORT_BIN_DIR}" "-Application Support Bin Dir-"
  275.     
  276.     fixBasicDirectoryPermissions
  277.     fixPermissions         admin 775  "${APPLICATION_SUPPORT_DIR}"
  278.     fixPermissions           admin 775  "${APPLICATION_SUPPORT_DIR}/Device Keys"
  279.     fixPermissions           admin 775  "${APPLICATION_SUPPORT_BIN_DIR}"
  280. }
  281.  
  282. # ----------------------------------------------------------------------------
  283. function prepareCameraControl()
  284. {
  285.     showInstallerState "Preparing Camera Control"
  286.     
  287.     if [ -z "${CAMERA_CONTROL_APP}" ]
  288.     then
  289.         CAMERA_CONTROL_APP="${APPLICATION_DIR}/IOXperts Camera Control${VARIANT}.app"
  290.     fi
  291.     
  292.     assertExistAppBundle  "${CAMERA_CONTROL_APP}" "-Camera Control App-"
  293.     
  294.     recurseFixPermissions  admin 755  "${CAMERA_CONTROL_APP}"
  295. }
  296.  
  297. # ----------------------------------------------------------------------------
  298. function removeCameraControl()
  299. {
  300.     moveVariantsToTrash "${APPLICATION_DIR}/IOXperts Camera Control" ".app"
  301. }
  302.  
  303. # ----------------------------------------------------------------------------
  304. function killDeviceMonitor()
  305. {
  306.     assertExistExecutable  "${INSTALLER_TOOLS_DIR}/KillDeviceMonitor" "-KillDeviceMonitor-"
  307.     "${INSTALLER_TOOLS_DIR}/KillDeviceMonitor"
  308. }
  309.  
  310. # ----------------------------------------------------------------------------
  311. function removeDeviceMonitors()
  312. {
  313.     DEVICE_MONITOR="${STARTUP_ITEMS}/IOXpertsDeviceMonitor"
  314.     SYSTEM_DEVICE_MONITOR="${SYSTEM_STARTUP_ITEMS}/IOXpertsDeviceMonitor"
  315.  
  316.     moveToTrash "${DEVICE_MONITOR}"
  317.     moveToTrash "${SYSTEM_DEVICE_MONITOR}"
  318. }
  319.  
  320. # ----------------------------------------------------------------------------
  321. function prepareDeviceMonitor()
  322. {
  323.     showInstallerState "Preparing Device Monitor"
  324.     
  325.     if [[ -z "${DEVICE_MONITOR}" && -z "${DEVICE_MONITOR_APP}" ]]
  326.     then
  327.         DEVICE_MONITOR="${STARTUP_ITEMS}/IOXpertsDeviceMonitor"
  328.         DEVICE_MONITOR_APP="${DEVICE_MONITOR}/ioxdeviced${VARIANT}.app"
  329.         DEVICE_MONITOR_EXECUTABLE="${DEVICE_MONITOR_APP}/Contents/MacOS/ioxdeviced${VARIANT}"
  330.     else
  331.         assertDefinedString "${DEVICE_MONITOR}" "-DEVICE_MONITOR-"
  332.         assertDefinedString "${DEVICE_MONITOR_APP}" "-DEVICE_MONITOR_APP-"
  333.         # local exe=`basename -s ".app" "${DEVICE_MONITOR_APP}"`
  334.         local exe=`basename "${DEVICE_MONITOR_APP}" ".app"`
  335.         echo "basename ${exe}"
  336.         #exe=`echo ${exe} | sed -e 's/\.app$//'`
  337.         #echo "pDM() - no ext ${exe}"
  338.         assertDefinedString "${exe}"  "-exe-"
  339.         DEVICE_MONITOR_EXECUTABLE="${DEVICE_MONITOR_APP}/Contents/MacOS/${exe}"
  340.     fi
  341.     local DEVICE_MONITOR_LAUNCH_EXECUTABLE="${DEVICE_MONITOR_APP}/Contents/Resources/Launcher"
  342.     
  343.     assertExistDir                        "${DEVICE_MONITOR}"                "DEVICE_MONITOR"
  344.     assertExistAppBundle                "${DEVICE_MONITOR_APP}"            "DEVICE_MONITOR_APP"
  345.     assertExistExecutable                "${DEVICE_MONITOR_EXECUTABLE}"  "DEVICE_MONITOR_EXECUTABLE"
  346.     assertExistExecutable                "${DEVICE_MONITOR_LAUNCH_EXECUTABLE}"            "DEVICE_MONITOR_LAUNCH_EXECUTABLE"
  347.     
  348.     recurseFixPermissions  wheel 755    "${DEVICE_MONITOR}"
  349.     # recurseFixOwnership    wheel nobody        "${DEVICE_MONITOR}"
  350.     recurseFixOwnership   wheel root    "${DEVICE_MONITOR}"
  351.     set -x
  352.     /bin/chmod                    6755    "${DEVICE_MONITOR_EXECUTABLE}"
  353.     /bin/chmod                   664    "${DEVICE_MONITOR_APP}/Contents/Info.plist"
  354.     /bin/chmod                   664    "${DEVICE_MONITOR_APP}/Contents/PkgInfo"
  355.     /bin/chmod                    6755    "${DEVICE_MONITOR_LAUNCH_EXECUTABLE}"
  356.     set +x
  357. }
  358.  
  359. # ----------------------------------------------------------------------------
  360. function prepareRegisterApp()
  361. {
  362.     showInstallerState "Preparing Registration App"
  363.     
  364.     if ! [ -z "${REGISTER_APP}" ]
  365.     then
  366.         local exe=`basename "${REGISTER_APP}" ".app"`
  367.         echo "basename ${exe}"
  368.         assertDefinedString "${exe}"  "-exe-"
  369.         REGISTER_EXECUTABLE="${REGISTER_APP}/Contents/MacOS/${exe}"
  370.         SNCREATE_EXECUTABLE="${REGISTER_APP}/Contents/Resources/SNCreate"
  371.     else
  372.         REGISTER_APP="${APPLICATION_SUPPORT_BIN_DIR}/IOXperts Register${VARIANT}.app"
  373.         REGISTER_EXECUTABLE="${REGISTER_APP}/Contents/MacOS/IOXperts Register${VARIANT}"
  374.         SNCREATE_EXECUTABLE="${REGISTER_APP}/Contents/Resources/SNCreate"
  375.     fi
  376.     
  377.     assertExistAppBundle                "${REGISTER_APP}"                "REGISTER_APP"
  378.     assertExistExecutable                "${REGISTER_EXECUTABLE}"        "REGISTER_EXECUTABLE"
  379.     assertExistExecutable                "${SNCREATE_EXECUTABLE}"        "SNCREATE_EXECUTABLE"
  380.     
  381.     recurseFixPermissions  wheel 755    "${REGISTER_APP}"
  382.     #recurseFixOwnership    wheel nobody   "${REGISTER_APP}"
  383.     recurseFixOwnership    wheel root   "${REGISTER_APP}"
  384.     set -x
  385.     /bin/chmod                   664    "${REGISTER_APP}/Contents/Info.plist"
  386.     /bin/chmod                   664    "${REGISTER_APP}/Contents/PkgInfo"
  387.  
  388.     /bin/chmod                    6755    "${REGISTER_EXECUTABLE}"
  389.     set +x
  390.  
  391.     recurseFixOwnership    wheel root   "${SNCREATE_EXECUTABLE}"
  392.     set -x
  393.     /bin/chmod                  2755    "${SNCREATE_EXECUTABLE}"
  394.     set +x
  395. }
  396.  
  397. # ----------------------------------------------------------------------------
  398. function removeRegisterApp()
  399. {
  400.     moveVariantsToTrash  "${APPLICATION_SUPPORT_BIN_DIR}/IOXperts Register" ".app"
  401.     moveVariantsToTrash  "${APPLICATION_SUPPORT_DIR}/IOXperts Register" ".app"
  402. }
  403.  
  404. # ----------------------------------------------------------------------------
  405. function prepareSessionMonitor()
  406. {
  407.     showInstallerState "Preparing Session Monitor"
  408.     
  409.     if ! [ -z "${SESSION_MONITOR_APP}" ]
  410.     then
  411.         # local exe=`basename -s ".app" "${SESSION_MONITOR_APP}"`
  412.         local exe=`basename "${SESSION_MONITOR_APP}" ".app"`
  413.         echo "basename ${exe}"
  414.         assertDefinedString "${exe}"  "-exe-"
  415.         SESSION_MONITOR_EXECUTABLE="${SESSION_MONITOR_APP}/Contents/MacOS/${exe}"
  416.     else
  417.         SESSION_MONITOR_APP="${APPLICATION_SUPPORT_BIN_DIR}/ioxsessiond${VARIANT}.app"
  418.         SESSION_MONITOR_EXECUTABLE="${SESSION_MONITOR_APP}/Contents/MacOS/ioxsessiond${VARIANT}"
  419.     fi
  420.     
  421.     assertExistAppBundle "${SESSION_MONITOR_APP}" "SESSION_MONITOR_APP"
  422.     assertExistExecutable "${SESSION_MONITOR_EXECUTABLE}"  "SESSION_MONITOR_EXECUTABLE"
  423.     
  424.     recurseFixPermissions  wheel 755  "${SESSION_MONITOR_APP}"
  425.     #recurseFixOwnership    wheel nobody   "${SESSION_MONITOR_APP}"
  426.     recurseFixOwnership    wheel root "${SESSION_MONITOR_APP}"
  427.     set -x
  428.     /bin/chmod                   664  "${SESSION_MONITOR_APP}/Contents/Info.plist"
  429.     /bin/chmod                   664  "${SESSION_MONITOR_APP}/Contents/PkgInfo"
  430.     set +x
  431. }
  432.  
  433. # ----------------------------------------------------------------------------
  434. function removeSessionMonitor()
  435. {
  436.     moveVariantsToTrash "${APPLICATION_SUPPORT_BIN_DIR}/ioxsessiond" ".app"
  437.     moveVariantsToTrash "${APPLICATION_SUPPORT_DIR}/ioxsessiond" ".app"
  438. }
  439.  
  440. # ----------------------------------------------------------------------------
  441. function prepareIdentifierApp()
  442. {
  443.     showInstallerState "Preparing Identifier App/Device Manager"
  444.     
  445.     if [ -z "${IDENTIFIER_APP}" ]
  446.     then
  447.         IDENTIFIER_APP="${APPLICATION_DIR}/Camera Identifier${VARIANT}.app"
  448.     fi
  449.     
  450.     assertExistAppBundle "${IDENTIFIER_APP}" "IDENTIFIER_APP"
  451.     recurseFixPermissions  wheel 755  "${IDENTIFIER_APP}"
  452.     recurseFixOwnership   wheel root  "${IDENTIFIER_APP}"
  453.     set -x
  454.     /bin/chmod                   664  "${IDENTIFIER_APP}/Contents/Info.plist"
  455.     /bin/chmod                   664  "${IDENTIFIER_APP}/Contents/PkgInfo"
  456.     set +x
  457.     # echo "${IDENTIFIER_APP}"
  458. }
  459.  
  460. # ----------------------------------------------------------------------------
  461. function removeIdentifierApp()
  462. {
  463.     moveVariantsToTrash "${APPLICATION_DIR}/Camera Identifier" ".app"
  464. }
  465.  
  466. # ----------------------------------------------------------------------------
  467. function prepareInstalledComponent()
  468. {
  469.     local COMPONENT="$1"
  470.     local DEFAULT_BASE_NAME="$2"
  471.     local DEFAULT_SUFFIX="$3"
  472.     assertDefinedString "${DEFAULT_BASE_NAME}"  "-DEFAULT_BASE_NAME-"
  473.     
  474.     if [ -z "${DEFAULT_SUFFIX}" ]
  475.     then
  476.         DEFAULT_SUFFIX=".component"
  477.     fi
  478.     
  479.     if [ -z "${COMPONENT}" ]
  480.     then
  481.         COMPONENT="${COMPONENTS_DIR}/${DEFAULT_BASE_NAME}${VARIANT}${DEFAULT_SUFFIX}"
  482.     fi
  483.     
  484.     assertExistAppBundle              "${COMPONENT}"
  485.     set -x
  486.     /usr/bin/chgrp            -R admin  "${COMPONENT}"
  487.     set +x
  488.  
  489. }
  490.  
  491. # ----------------------------------------------------------------------------
  492. function removeKexts()
  493. {
  494.     # Remove the obsolete kexts
  495.     moveToTrash "${SYSTEM_EXTENSIONS_DIR}/LogitechQuickCam.kext"
  496.     moveToTrash "${SYSTEM_EXTENSIONS_DIR}/IOXpertsWebcam.kext"
  497. }
  498.  
  499. # ----------------------------------------------------------------------------
  500. function removeObsoleteLogitechComponents()
  501. {
  502.     # Remove the obsolete components
  503.     # use only in logitech installer
  504.     moveToTrash "${COMPONENTS_DIR}/Logitech QuickCam.component"
  505. }
  506.  
  507. # ----------------------------------------------------------------------------
  508. function repairQuickTime()
  509. {
  510.     showInstallerState "Reparing QuickTime"
  511.     
  512.     assertExistExecutable        "${INSTALLER_TOOLS_DIR}/qt6fix" "-qt6fix-"
  513.  
  514.     # Clean up bugs in QT 6.0, 6.1 and 6.2
  515.     set -x
  516.     /bin/chmod                     555  "${INSTALLER_TOOLS_DIR}/qt6fix"
  517.     "${INSTALLER_TOOLS_DIR}/qt6fix"
  518.     set +x
  519. }
  520.  
  521. # ----------------------------------------------------------------------------
  522. function registerDeviceMonitorWithLaunchServices()
  523. {
  524.     showInstallerState "Registering Device Monitor with Launch Services"
  525.     
  526.     assertExistExecutable        "${INSTALLER_TOOLS_DIR}/RegisterApps" "-RegisterApps-"
  527.  
  528.     # Record the locations of various components in com.ioxperts.common prefs.
  529.     set -x
  530.     /bin/chmod                     555  "${INSTALLER_TOOLS_DIR}/RegisterApps"
  531.     "${INSTALLER_TOOLS_DIR}/RegisterApps" -m "${DEVICE_MONITOR_APP}"
  532.     rv=$?
  533.     set +x
  534.     bailOnError ${rv}
  535. }
  536.  
  537. # ----------------------------------------------------------------------------
  538. function registerAppsWithLaunchServices()
  539. {
  540.     showInstallerState "Registering Applications with Launch Services"
  541.     
  542.     assertExistFileSystemObject "${DEVICE_MONITOR_APP}"        "DEVICE_MONITOR_APP"
  543.     assertExistFileSystemObject "${REGISTER_APP}"            "REGISTER_APP"
  544.     assertExistFileSystemObject "${SESSION_MONITOR_APP}"    "SESSION_MONITOR_APP"
  545.     assertExistFileSystemObject "${IDENTIFIER_APP}"            "IDENTIFIER_APP"
  546.     assertExistExecutable        "${INSTALLER_TOOLS_DIR}/RegisterApps" "-RegisterApps-"
  547.     
  548.     set -x
  549.     /bin/chmod                     555  "${INSTALLER_TOOLS_DIR}/RegisterApps"
  550.     "${INSTALLER_TOOLS_DIR}/RegisterApps"             "${DEVICE_MONITOR_APP}" \
  551.                                                      "${REGISTER_APP}" \
  552.                                                      "${SESSION_MONITOR_APP}" \
  553.                                                      "${IDENTIFIER_APP}"
  554.     rv=$?
  555.     set +x
  556.     bailOnError ${rv}
  557. }
  558.  
  559. # ----------------------------------------------------------------------------
  560. # TODO - parameterize better
  561. function registerDeviceMonitorAsGlobalLoginItem()
  562. {
  563.     local removalPat="ioxdeviced"
  564.     if ! [ -z $1 ]
  565.     then
  566.         removalPat="$1"
  567.     fi
  568.     
  569.     showInstallerState "Registering Device Monitor as Global Login Item"
  570.     
  571.     assertExistAppBundle  "${DEVICE_MONITOR_APP}" "-DeviceMonitor-"
  572.     assertExistExecutable "${INSTALLER_TOOLS_DIR}/AddGlobalLoginItem" "-RegisterApps-"
  573.     
  574.     set -x
  575.     /bin/chmod                     555  "${INSTALLER_TOOLS_DIR}/AddGlobalLoginItem"
  576.     "${INSTALLER_TOOLS_DIR}/AddGlobalLoginItem"        "${DEVICE_MONITOR_APP}" "${removalPat}"
  577.     rv=$?
  578.     set +x
  579.     bailOnError ${rv}
  580. }
  581.  
  582. # ----------------------------------------------------------------------------
  583. function registerSessionMonitorAsGlobalLoginItem()
  584. {
  585.     showInstallerState "Registering Session Monitor as Global Login Item"
  586.     
  587.     assertExistAppBundle  "${SESSION_MONITOR_APP}" "-SessionMonitor-"
  588.     assertExistExecutable "${INSTALLER_TOOLS_DIR}/AddGlobalLoginItem" "-RegisterApps-"
  589.     
  590.     set -x
  591.     /bin/chmod                     555  "${INSTALLER_TOOLS_DIR}/AddGlobalLoginItem"
  592.     "${INSTALLER_TOOLS_DIR}/AddGlobalLoginItem"        "${SESSION_MONITOR_APP}" "ioxsessiond"
  593.     rv=$?
  594.     set +x
  595.     bailOnError ${rv}
  596. }
  597.  
  598. # ----------------------------------------------------------------------------
  599. # If the SM can't launch Register after a clean install, consider
  600. # adding this call to the postflight script.  It sets the prefs so the launch
  601. # code for Register can find the Register app by full path.
  602.  
  603. function setAppLocationPreferences()
  604. {
  605.     showInstallerState "Setting Application Location Preferences"
  606.     
  607.     assertExistAppBundle  "${REGISTER_APP}" "-Registration App-"
  608.     assertExistAppBundle  "${SESSION_MONITOR_APP}" "-Session Monitor App-"
  609.     assertExistExecutable "${INSTALLER_TOOLS_DIR}/SetInstallationPrefs" "-SetInstallationPrefs-"
  610.                                             
  611.     set -x
  612.     /bin/chmod                     555  "${INSTALLER_TOOLS_DIR}/SetInstallationPrefs"
  613.     "${INSTALLER_TOOLS_DIR}/SetInstallationPrefs" -purchase "${REGISTER_APP}" \
  614.                                                   -sessionMonitor "${SESSION_MONITOR_APP}"
  615.     rv=$?
  616.     set +x
  617.     
  618.     bailOnError ${rv}
  619. }
  620.  
  621. # ----------------------------------------------------------------------------
  622. function startDeviceMonitor()
  623. {
  624.     showInstallerState "Starting Device Monitor"
  625.     
  626.     assertExistExecutable "${INSTALLER_TOOLS_DIR}/Launcher" "-Launcher-"
  627.     assertExistAppBundle "${DEVICE_MONITOR_APP}" "DEVICE_MONITOR_APP"
  628.  
  629.     # Start the Device Monitor
  630.     # TODO - Require Reboot or logout/login 
  631.     set -x
  632.     "${INSTALLER_TOOLS_DIR}/Launcher" "${DEVICE_MONITOR_APP}"
  633.     rv=$?
  634.     set +x
  635.     bailOnError ${rv}
  636.     
  637.     # TODO - add dialog - reboot?"yes":"no"
  638.     #  if "no" - start device monitor
  639.     #  if "yes" - reboot
  640. }
  641.  
  642. # ----------------------------------------------------------------------------
  643. function killSessionMonitor()
  644. {
  645.     showInstallerState "Stopping Session Monitor"
  646.     
  647.     assertExistExecutable "${INSTALLER_TOOLS_DIR}/KillSessionMonitor" "-KillSessionMonitor-"
  648.     set -x
  649.     "${INSTALLER_TOOLS_DIR}/KillSessionMonitor"
  650.     set +x
  651. }
  652.  
  653. # ----------------------------------------------------------------------------
  654. function startSessionMonitor()
  655. {
  656.     showInstallerState "Starting Session Monitor"
  657.     
  658.     # assertExistExecutable "${SESSION_MONITOR_EXECUTABLE}" "SESSION_MONITOR_EXECUTABLE"
  659.     assertExistExecutable "${INSTALLER_TOOLS_DIR}/Launcher" "-Launcher-"
  660.     assertExistAppBundle "${SESSION_MONITOR_APP}" "SESSION_MONITOR_APP"
  661.  
  662.     # Start the Session Monitor
  663.     # TODO - Require Reboot or logout/login 
  664.     set -x
  665.     "${INSTALLER_TOOLS_DIR}/Launcher" "${SESSION_MONITOR_APP}"
  666.     set +x
  667.     
  668.     # TODO - bailOnError $?
  669. }
  670.  
  671. # ----------------------------------------------------------------------------
  672. function startIdentifierApp()
  673. {
  674.     showInstallerState "Starting Identifier"
  675.     
  676.     # assertExistExecutable "${SESSION_MONITOR_EXECUTABLE}" "SESSION_MONITOR_EXECUTABLE"
  677.     assertExistExecutable "${INSTALLER_TOOLS_DIR}/Launcher" "-Launcher-"
  678.     assertExistAppBundle "${IDENTIFIER_APP}" "IDENTIFIER_APP"
  679.  
  680.     # Start the Camera Identifier
  681.     set -x
  682.     sleep 3
  683.     # sleep is a hack to make sure the SM and DM have time to launch.
  684.     "${INSTALLER_TOOLS_DIR}/Launcher" "${IDENTIFIER_APP}"
  685.     set +x
  686.     
  687.     # TODO - bailOnError $?
  688. }
  689.  
  690. # ----------------------------------------------------------------------------
  691. function uninstall()
  692. {
  693.     showInstallerState "Uninstalling...."
  694.  
  695.     assertExistDir          "${INSTALLER_TOOLS_DIR}"
  696.     assertExistExecutable "${INSTALLER_TOOLS_DIR}/MoveToTrash" "-MoveToTrash-"
  697.     assertExistExecutable "${INSTALLER_TOOLS_DIR}/KillDeviceMonitor" "-KillDeviceMonitor-"
  698.     assertExistExecutable "${INSTALLER_TOOLS_DIR}/KillSessionMonitor" "-KillSessionMonitor-"
  699.     assertExistExecutable "${INSTALLER_TOOLS_DIR}/ComponentTool" "-ComponentTool-"
  700.     assertExistFile          "${INSTALLER_TOOLS_DIR}/IOXpertsUninstaller.sh" "-Uninstaller Script-"
  701.     assertExistFile       "${INSTALLER_TOOLS_DIR}/UninstallerTools.sh" "-Uninstaller Tools-"
  702.  
  703.     set -x
  704.     /bin/chmod                     555  "${INSTALLER_TOOLS_DIR}/IOXpertsUninstaller.sh"
  705.     /bin/chmod                    2555  "${INSTALLER_TOOLS_DIR}/MoveToTrash"
  706.     /bin/chmod                     555  "${INSTALLER_TOOLS_DIR}/KillDeviceMonitor"
  707.     /bin/chmod                     555  "${INSTALLER_TOOLS_DIR}/KillSessionMonitor"
  708.     /bin/chmod                     555  "${INSTALLER_TOOLS_DIR}/ComponentTool"
  709.     set +x
  710.  
  711.     assertExistExecutable "${INSTALLER_TOOLS_DIR}/IOXpertsUninstaller.sh" "-Uninstaller Script-"
  712.     
  713.     set -x
  714.     "${INSTALLER_TOOLS_DIR}/IOXpertsUninstaller.sh" trash \
  715.                                                     -bin "${INSTALLER_TOOLS_DIR}" \
  716.                                                     -scripts "${INSTALLER_TOOLS_DIR}" \
  717.                                                     -installer -verbose -removeinstaller -clearprefs \
  718.                                                     $1 $2 $3 $4 $5 $6 $7 $8 $9
  719.     # # TRY ${@[@]} instead of $1...$9
  720.     rv=$?  > /dev/null 2>&1
  721.     set +x
  722.     bailOnError ${rv}
  723. }
  724.  
  725. # ----------------------------------------------------------------------------
  726. # Prior to DM 1.1b54 (prefs version 2) - device monitor prefs can be corrupted
  727. # by bugs in the DM.
  728. # TODO - correct handling of MoveToTrash wrt 10.2 and consistent behavior in installer tools.
  729.  
  730. function upgradeOrRemoveDeviceMonitorPrefs()
  731. {
  732.     showInstallerState "Examining Device Monitor Preferences...."
  733.     
  734.     assertExistDir          "${INSTALLER_TOOLS_DIR}"
  735.     
  736.     if [ -e "${INSTALLER_TOOLS_DIR}/DMPrefsTool" ]
  737.     then
  738.         set -x
  739.         /bin/chmod                     555  "${INSTALLER_TOOLS_DIR}/DMPrefsTool"
  740.         set +x
  741.     fi
  742.  
  743.     if [ -x "${INSTALLER_TOOLS_DIR}/DMPrefsTool" ]
  744.     then
  745.         # Prior to this version - remove the DM preferences
  746.         "${INSTALLER_TOOLS_DIR}/DMPrefsTool" -version "1.1b54" "2"
  747.         local rv=$?
  748.         echo "DMPrefsTool -version 1.1b54 2     returns ${rv}"
  749.         if [ ${rv} -eq 0 ]
  750.         then
  751.             echo "Removing Device Monitor Preferences"
  752.             /bin/rm -f "/Library/Preferences/com.ioxperts.devicemonitor.plist"
  753.         fi
  754.     fi
  755.     echo " "
  756. }
  757.  
  758. # ----------------------------------------------------------------------------
  759. # TODO - add point release as well, maybe beta and build num?
  760. # i.e. support not just X.Y bug X.Y.ZaW
  761.  
  762. function IsOSBefore()
  763. {
  764.     local testMajor=$1
  765.     local testMinor=$2
  766.     
  767.     if [ -z "${testMajor}" ]
  768.     then
  769.         testMajor=0
  770.     fi
  771.     
  772.     if [ -z "${testMinor}" ]
  773.     then
  774.         testMinor=0
  775.     fi
  776.     
  777.     local IS_PRE=1
  778.     if [ -x "/usr/bin/sw_vers" ]
  779.     then
  780.         local _V=`/usr/bin/sw_vers | grep ProductVersion | sed -e 's/ProductVersion:[^0-9]*//'`
  781.         local maj=`echo ${_V} | sed -e 's/\..*//'`
  782.         local min=`echo ${_V} | sed -e 's/[0-9]*\.//' -e 's/\..*//'`
  783.         # echo V ${_V}
  784.         # echo "MAJ '${maj}'"
  785.         # echo "MIN '${min}'"
  786.  
  787.         if  [ ${maj} -gt ${testMajor} ]
  788.         then
  789.             IS_PRE=0
  790.         elif [[ ${maj} -eq ${testMajor} && ${min} -ge ${testMinor} ]]
  791.         then
  792.             IS_PRE=0
  793.         fi
  794.     fi
  795.     return ${IS_PRE}
  796. }
  797.  
  798.